// 资源 cpu内存
console.log(process.memoryUsage())
console.log(process.cpuUsage())

// 运行环境：运行目录、node环境、cpu架构、用户环境、系统平台
console.log('当前工作目录 -> ' + process.cwd())
console.log('当前node环境 -> ' + process.version)
console.log(process.versions)  //当前node环境详细信息
console.log('当前cpu架构 -> ' + process.arch)
console.log(process.env.NODE_ENV)
console.log('当前系统环境变量 -> ' + process.env.PATH)

console.log('当前用户环境 -> ' + process.env.USERPROFILE)
console.log('当前系统平台 -> ' + process.platform)


// 运行状态: 启动参数, pid, 运行时间
console.log(process.argv)
console.log(process.argv0)  //可以拿到第0个参数
console.log(process.pid)

console.log(process.uptime())

// 事件
process.on('exit', (code) => {
  console.log('exit ->', code)
})

process.on('beforeExit', (code) => {
  console.log('before exit ->', code)
})

console.log('代码执行完了')

//process.exit()



// 标准的输入 输出
console.log = function (data) {
  process.stdout.write('标准化输出 ->' + data + '\n')
}

console.log('hi')
console.log('world')

const fs = require('fs')
fs.createReadStream('./test.txt')
  .pipe(process.stdout)

process.stdin.pipe(process.stdout)

process.stdin.setEncoding('utf-8')
process.stdin.on('readable', () => {
  let chunk = process.stdin.read()
  if (chunk != null) {
    process.stdout.write('data -> ' + chunk)
  }
})